package org.mspring.platform.weibo.tencent.entity.dto;

import java.util.Map;

import org.apache.commons.collections.MapUtils;
import org.mspring.platform.weibo.tencent.TencentResultUtils;

/**
 * 授权结果
 *
 * @author Gao Youbo
 * @since 2014年5月23日
 */
public class TencentAuth {
    private String openid;
    private String openkey;
    private String accessToken;
    private String refreshToken;
    private long expiresIn;
    private String name;
    private String nick;

    /**
     * 解析授权结果，获取TencentAuth对象
     *
     * @param result
     * @return
     */
    public static TencentAuth getInstance(String result) {
        Map<String, String> map = TencentResultUtils.getResultMap(result);
        String accessToken = MapUtils.getString(map, "access_token");
        long expiresIn = MapUtils.getLongValue(map, "expires_in");
        String refreshToken = MapUtils.getString(map, "refresh_token");
        String name = MapUtils.getString(map, "name");
        String nick = MapUtils.getString(map, "nick");
        TencentAuth tencentAuthResult = new TencentAuth();
        tencentAuthResult.setAccessToken(accessToken);
        tencentAuthResult.setRefreshToken(refreshToken);
        tencentAuthResult.setExpiresIn(expiresIn);
        tencentAuthResult.setName(name);
        tencentAuthResult.setNick(nick);
        return tencentAuthResult;
    }

    public String getOpenid() {
        return openid;
    }

    public void setOpenid(String openid) {
        this.openid = openid;
    }

    public String getOpenkey() {
        return openkey;
    }

    public void setOpenkey(String openkey) {
        this.openkey = openkey;
    }

    public String getAccessToken() {
        return accessToken;
    }

    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }

    public String getRefreshToken() {
        return refreshToken;
    }

    public void setRefreshToken(String refreshToken) {
        this.refreshToken = refreshToken;
    }

    public long getExpiresIn() {
        return expiresIn;
    }

    public void setExpiresIn(long expiresIn) {
        this.expiresIn = expiresIn;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getNick() {
        return nick;
    }

    public void setNick(String nick) {
        this.nick = nick;
    }
}
